import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { BookingEmergencyIncidentApi } from '#/api/spa/booking/emergencyincident';

import { z } from '#/adapter/form';
import {
    DICT_TYPE,
    getDictOptions,
    getRangePickerDefaultProps,
} from '#/utils';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'incidentCode',
      label: '突发情况编码',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入突发情况编码',
      },
    },
    {
      fieldName: 'incidentType',
      label: '突发情况类型',
      rules: 'required',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择突发情况类型',
      },
    },
    {
      fieldName: 'incidentTitle',
      label: '突发情况标题',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入突发情况标题',
      },
    },
    {
      fieldName: 'incidentDescription',
      label: '突发情况描述',
      rules: 'required',
      component: 'RichTextarea',
    },
    {
      fieldName: 'incidentSeverity',
      label: '严重程度',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入严重程度',
      },
    },
    {
      fieldName: 'affectedAreas',
      label: '影响区域',
      component: 'Input',
      componentProps: {
        placeholder: '请输入影响区域',
      },
    },
    {
      fieldName: 'affectedResources',
      label: '影响资源',
      component: 'Input',
      componentProps: {
        placeholder: '请输入影响资源',
      },
    },
    {
      fieldName: 'affectedOrders',
      label: '影响订单',
      component: 'Input',
      componentProps: {
        placeholder: '请输入影响订单',
      },
    },
    {
      fieldName: 'incidentStartTime',
      label: '突发情况开始时间',
      rules: 'required',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'estimatedResolutionTime',
      label: '预估解决时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'actualResolutionTime',
      label: '实际解决时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'incidentDuration',
      label: '突发情况持续时间(分钟)',
      component: 'Input',
      componentProps: {
        placeholder: '请输入突发情况持续时间(分钟)',
      },
    },
    {
      fieldName: 'incidentStatus',
      label: '突发情况状态',
      rules: 'required',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'reporterId',
      label: '报告人ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入报告人ID',
      },
    },
    {
      fieldName: 'assigneeId',
      label: '处理人ID',
      component: 'Input',
      componentProps: {
        placeholder: '请输入处理人ID',
      },
    },
    {
      fieldName: 'resolutionNotes',
      label: '解决备注',
      component: 'Input',
      componentProps: {
        placeholder: '请输入解决备注',
      },
    },
    {
      fieldName: 'impactLevel',
      label: '影响程度',
      component: 'Input',
      componentProps: {
        placeholder: '请输入影响程度',
      },
    },
    {
      fieldName: 'affectedCustomerCount',
      label: '受影响客户数量',
      component: 'Input',
      componentProps: {
        placeholder: '请输入受影响客户数量',
      },
    },
    {
      fieldName: 'estimatedLoss',
      label: '预估损失',
      component: 'Input',
      componentProps: {
        placeholder: '请输入预估损失',
      },
    },
    {
      fieldName: 'storeId',
      label: '门店ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入门店ID',
      },
    },
    {
      fieldName: 'orgId',
      label: '组织ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入组织ID',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'incidentCode',
      label: '突发情况编码',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入突发情况编码',
      },
    },
    {
      fieldName: 'incidentType',
      label: '突发情况类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择突发情况类型',
      },
    },
    {
      fieldName: 'incidentTitle',
      label: '突发情况标题',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入突发情况标题',
      },
    },
    {
      fieldName: 'incidentDescription',
      label: '突发情况描述',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入突发情况描述',
      },
    },
    {
      fieldName: 'incidentSeverity',
      label: '严重程度',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入严重程度',
      },
    },
    {
      fieldName: 'affectedAreas',
      label: '影响区域',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入影响区域',
      },
    },
    {
      fieldName: 'affectedResources',
      label: '影响资源',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入影响资源',
      },
    },
    {
      fieldName: 'affectedOrders',
      label: '影响订单',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入影响订单',
      },
    },
    {
      fieldName: 'incidentStartTime',
      label: '突发情况开始时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'estimatedResolutionTime',
      label: '预估解决时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'actualResolutionTime',
      label: '实际解决时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'incidentDuration',
      label: '突发情况持续时间(分钟)',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入突发情况持续时间(分钟)',
      },
    },
    {
      fieldName: 'incidentStatus',
      label: '突发情况状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择突发情况状态',
      },
    },
    {
      fieldName: 'reporterId',
      label: '报告人ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入报告人ID',
      },
    },
    {
      fieldName: 'assigneeId',
      label: '处理人ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入处理人ID',
      },
    },
    {
      fieldName: 'resolutionNotes',
      label: '解决备注',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入解决备注',
      },
    },
    {
      fieldName: 'impactLevel',
      label: '影响程度',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入影响程度',
      },
    },
    {
      fieldName: 'affectedCustomerCount',
      label: '受影响客户数量',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入受影响客户数量',
      },
    },
    {
      fieldName: 'estimatedLoss',
      label: '预估损失',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入预估损失',
      },
    },
    {
      fieldName: 'storeId',
      label: '门店ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入门店ID',
      },
    },
    {
      fieldName: 'orgId',
      label: '组织ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入组织ID',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<BookingEmergencyIncidentApi.BookingEmergencyIncident>['columns'] {
  return [
    {
      field: 'id',
      title: '突发情况ID',
      minWidth: 120,

    },
    {
      field: 'incidentCode',
      title: '突发情况编码',
      minWidth: 120,

    },
    {
      field: 'incidentType',
      title: '突发情况类型',
      minWidth: 120,

    },
    {
      field: 'incidentTitle',
      title: '突发情况标题',
      minWidth: 120,

    },
    {
      field: 'incidentDescription',
      title: '突发情况描述',
      minWidth: 120,

    },
    {
      field: 'incidentSeverity',
      title: '严重程度',
      minWidth: 120,

    },
    {
      field: 'affectedAreas',
      title: '影响区域',
      minWidth: 120,

    },
    {
      field: 'affectedResources',
      title: '影响资源',
      minWidth: 120,

    },
    {
      field: 'affectedOrders',
      title: '影响订单',
      minWidth: 120,

    },
    {
      field: 'incidentStartTime',
      title: '突发情况开始时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'estimatedResolutionTime',
      title: '预估解决时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'actualResolutionTime',
      title: '实际解决时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'incidentDuration',
      title: '突发情况持续时间(分钟)',
      minWidth: 120,

    },
    {
      field: 'incidentStatus',
      title: '突发情况状态',
      minWidth: 120,

    },
    {
      field: 'reporterId',
      title: '报告人ID',
      minWidth: 120,

    },
    {
      field: 'assigneeId',
      title: '处理人ID',
      minWidth: 120,

    },
    {
      field: 'resolutionNotes',
      title: '解决备注',
      minWidth: 120,

    },
    {
      field: 'impactLevel',
      title: '影响程度',
      minWidth: 120,

    },
    {
      field: 'affectedCustomerCount',
      title: '受影响客户数量',
      minWidth: 120,

    },
    {
      field: 'estimatedLoss',
      title: '预估损失',
      minWidth: 120,

    },
    {
      field: 'storeId',
      title: '门店ID',
      minWidth: 120,

    },
    {
      field: 'orgId',
      title: '组织ID',
      minWidth: 120,

    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}

